package com.yc.jpyy.vehicle.service.imp;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.vehicle.dao.VehicleDao;
import com.yc.jpyy.vehicle.service.VehicleService;

@Service
public class VehicleServiceImpl extends BaseService implements VehicleService {
 

@Autowired
private VehicleDao vehicleDao;

@Override
public Map<String, Object> update(Map<String, Object> paramsMap)
		throws DataAccessException {
	//HandlerDataSource.setDataSource("bizDataSource");
	Map<String,Object> resultMap = new HashMap<>();
	//List<Map<String,Object>> list = vehicleDao.select(paramsMap);
	int i = vehicleDao.update(paramsMap);
	if(i <= 0){
		resultMap.put("message", "出错");
	}else{
		//int j = i / 0;
		//resultMap.put("message", "异常");
		int j = vehicleDao.updates(paramsMap);
		if(j <= 0){
			resultMap.put("message", "出错");
		}
	}
	return resultMap;
}

@Override
public Map<String, Object> selects(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<Map<String,Object>> list = vehicleDao.selects(paramsMap);
	resultMap.put("ListData",list);
	return resultMap;
}

@Override
public Map<String,Object> checkTicket(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int count =  vehicleDao.checkTicket(paramsMap);
	if(count > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "该票号已经存在");
		resultMap.put("ListData",1);
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "票号不存在");
		resultMap.put("ListData", 0);
	}
	return resultMap;
}

@Override
public Map<String,Object> checkTickets(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<String> ticketNums = vehicleDao.checkTickets(paramsMap);
	if(ticketNums != null && ticketNums.size() > 0){
		String num = StringUtils.join(ticketNums.toArray(), ",");
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "票号存在重复");
		resultMap.put("ListData",num);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "不存在重复票号");
		resultMap.put("ListData",0);
	}
	return resultMap;
}


@Override
public  Map<String,Object> addTicket(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//分段间隔值
	String interval = Optional.ofNullable(paramsMap.get("interval")).orElse("50").toString();
	int size = Integer.parseInt(interval.isEmpty() || interval.equals("") ? "50" :interval);
	int startNo = Integer.parseInt(paramsMap.get("startno").toString());
	int endNo = Integer.parseInt(paramsMap.get("endno").toString());
	//票总数
	int ticketCount = endNo - startNo + 1;
	//size张票属于一组数据，票组数
	int intervalCount = ticketCount % size == 0 ? ticketCount / size : ticketCount / size + 1;
	for(int k = 0;k < intervalCount;k ++){
		int firstNo = size * k + startNo;
		int secondNo = 0 ;
		if(k + 1 == intervalCount){
			secondNo = endNo;
		}else{
			secondNo = size * (k + 1) -1 + startNo;
		}
		paramsMap.put("startno",firstNo);
		paramsMap.put("endno",secondNo);
		//新增票数据
		int i = vehicleDao.addTicket(paramsMap);
		if(i <= 0){
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg ", "票新增失败");
		}else{
			List<Map<String,Object>> tiketMapList = new ArrayList<Map<String,Object>>();
			for(int j = firstNo;j <= secondNo;j ++){
				Map<String,Object> tiketMap = new HashMap<>();
				tiketMap.put("tickeid", paramsMap.get("tickeId"));
				tiketMap.put("ticketype", paramsMap.get("ticketype"));
				tiketMap.put("creatuser", paramsMap.get("creatuser"));
				tiketMap.put("usertype", paramsMap.get("usedept"));
				tiketMap.put("tickenum", j);
				tiketMap.put("dbcode", paramsMap.get("dbcode"));
				tiketMap.put("yeardate", paramsMap.get("yeardate"));
				tiketMap.put("usedeptname", paramsMap.get("usedeptname"));
				tiketMapList.add(tiketMap);
			}
			//新增票详细
			int l = vehicleDao.addTiketDetail(tiketMapList);
			if(l <= 0){
				resultMap.put("returnCode", 0);
				resultMap.put("returnMsg", "新增失败");
			}else{
				resultMap.put("returnCode", 1);
				resultMap.put("returnMsg", "新增成功");
			}
		}
	}
	return resultMap;
}

@Override
public Map<String,Object> queryTiket(Map<String,Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	List<Map<String,Object>> ticketList = vehicleDao.queryTiket(paramsMap);
	int ticketCounts = vehicleDao.queryTiketCounts(paramsMap);
	if(ticketList != null && ticketList.size() > 0){
		//PageBean pagebean = getPageBean(ticketList,ticketCounts,pagesize,pagenum);
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",ticketList);
		resultMap.put("TotalCount",ticketCounts);
		resultMap.put("TotalPage",ticketCounts % pagesize >0 ? ticketCounts/pagesize + 1 : ticketCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String,Object> getTicketNum(Map<String,Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//查询票证号
	Map<String, Object> ticketNum = vehicleDao.getTicketNum(paramsMap); 
	if(ticketNum != null && ticketNum.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "操作成功");
		resultMap.put("ListData", ticketNum);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "未查询到数据");
	}
	return resultMap;
}

@Override
public Map<String,Object> updateTicketDetailStatus(Map<String,Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	paramsMap.put("ids",paramsMap.get("ids").toString().split(","));
	//更新票证状态
	int count  = vehicleDao.updateTicketDetailStatus(paramsMap); 
	if(count > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}
	return resultMap;
}

@Override
public Map<String,Object> updateTikeStatus(Map<String,Object> paramsMap)
		throws Exception {
	Map<String,Object> resultMap = new HashMap<>();
	//查询主表的结束编号
	Map<String,Object> ticketMap = vehicleDao.getTikeById(paramsMap); 
	//更新票证状态
	int count  = vehicleDao.updateTikeStatus(paramsMap); 
	if(count > 0){
		if(!ticketMap.get("EndNo").toString().equals(paramsMap.get("currentno").toString())){
			int startNo = Integer.parseInt(paramsMap.get("currentno").toString()) + 1;
			int endNo = Integer.parseInt(ticketMap.get("EndNo").toString());
			paramsMap.put("startno",startNo);
			paramsMap.put("endno",endNo);
			//新增票数据
			paramsMap.put("ticketype", ticketMap.get("TickeType"));
			paramsMap.put("status", 1);
			paramsMap.put("isuse", 0);
			paramsMap.put("createman", ticketMap.get("CreateMan"));
			paramsMap.put("yeardate", ticketMap.get("YearDate"));
			DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
			LocalDateTime localDateTime = LocalDateTime.now();
			String localTime = df.format(localDateTime);
			paramsMap.put("createtime", localTime);
			int i = vehicleDao.addTicket(paramsMap);
			if(i <= 0){
				throw new Exception();
			}else{
				//把原来主表对应的明细表(startNo-endNo之间的子表)关联到当前新增的主表上,并把相应的字段置空
				int k = vehicleDao.updateTicketDtailRelation(paramsMap);
				if(k > 0){
					resultMap.put("returnCode", 1);
					resultMap.put("returnMsg", "缴回成功");
				}else{
					throw new Exception();
				}
			}
		}
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "缴回成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "缴回失败");
	}
	return resultMap;
}

@Override
public Map<String,Object> getTikeById(Map<String,Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//更新票证状态
	Map<String,Object> ticketMap  = vehicleDao.getTikeById(paramsMap); 
	if(ticketMap != null && ticketMap.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "操作成功");
		resultMap.put("ListData", ticketMap);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "未查询到数据");
	}
	return resultMap;
}


@Override
public Map<String,Object> addVehicle(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//新增车辆
	int i = vehicleDao.addVehicle(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "新增失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "新增成功");
		resultMap.put("ListData", paramsMap.get("ID"));
	}
	return resultMap;
}

@Override
public Map<String,Object> queryVehicle(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
	paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
	List<Map<String,Object>> vehicleList = vehicleDao.queryVehicle(paramsMap);
	int vehicleCounts = vehicleDao.queryVehicleCounts(paramsMap);
	if(vehicleList != null && vehicleList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",vehicleList);
		resultMap.put("TotalCount",vehicleCounts);
		resultMap.put("TotalPage",vehicleCounts % pagesize >0 ? vehicleCounts/pagesize + 1 : vehicleCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String,Object> updateVehicle(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.updateVehicle(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> checkVehicleId(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//查询是否已经存在拥有该信息的车辆
	int i = vehicleDao.checkVehicleId(paramsMap);
	if(i > 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "数据重复");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "操作成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> queryVehicleById(int id)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> vehicleInfo = vehicleDao.queryVehicleById(id);
	if(vehicleInfo != null){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData", vehicleInfo);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统查询不到该条信息");
	}
	return resultMap;
}


@Override
public Map<String, Object> addVehicleOperateLog(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.addVehicleOperateLog(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "新增失败");
	}else{
		paramsMap.put("id", paramsMap.get("vid").toString().split(","));
		//更改车辆状态
		int count = vehicleDao.updateForStatus(paramsMap);
		if(count < 0){
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "车辆状态更改失败");
		}else{
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "新增成功");
		}
	}
	return resultMap;
}

@Override
public Map<String, Object> queryVehicleOperateLog(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	paramsMap.put("operatetypes", Optional.ofNullable(paramsMap.get("operatetype")).orElse("").toString().split(","));
	List<Map<String,Object>> vehicleLogList = vehicleDao.queryVehicleOperateLog(paramsMap);
	int vehicleLogCounts = vehicleDao.queryVehicleCounts(paramsMap);
	if(vehicleLogList != null && vehicleLogList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",vehicleLogList);
		resultMap.put("TotalCount",vehicleLogCounts);
		resultMap.put("TotalPage",vehicleLogCounts % pagesize >0 ? vehicleLogCounts/pagesize + 1 : vehicleLogCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("errorCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> queryVehicleOperateById(int id)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> vehicleLogInfo = vehicleDao.queryVehicleOperateById(id);
	if(vehicleLogInfo != null){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData", vehicleLogInfo);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统查询不到该条信息");
	}
	return resultMap;
}

@Override
public Map<String,Object> updateForCheck(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.updateForCheck(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> updateForStatus(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.updateForStatus(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> updateForLock(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.updateForLock(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> updateForImage(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.updateForImage(paramsMap);
	if(i <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

/*@Override
public Map<String, Object> vehicleCheckYears(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	String checkyeartype = paramsMap.get("checkyeartype").toString();
	String[] ids =  paramsMap.get("ids").toString().split(",");
	paramsMap.put("ids", ids);
	if(checkyeartype.equals("1") || checkyeartype.equals("2")){
		//比年审日期提前四个月-->年审日期之间 ||大于年审日期-->小于年审日期加一年之间
        //更改车辆的年审日期=年审日期加一年 
        int count = vehicleDao.updateForAddOneChekYear(paramsMap);
        if( count > 0){
        	resultMap.put("returnCode", 1);
        	resultMap.put("ListData", count);
    		resultMap.put("returnMsg", "年审成功");
        }else{
        	resultMap.put("returnCode", 0);
    		resultMap.put("returnMsg", "年审失败");
        }
	}else if(checkyeartype.equals("3")){
		//大于年审日期加一年
		//更改车辆你那身日期加一年（月日还取原来的月日）
		int count = vehicleDao.updateForAddCurrentChekYear(paramsMap);
		if( count > 0){
        	resultMap.put("returnCode", 1);
    		resultMap.put("returnMsg", "年审成功");
    		resultMap.put("ListData", count);
        }else{
        	resultMap.put("returnCode", 0);
    		resultMap.put("returnMsg", "年审失败");
        }
	}
	return resultMap;
}
*/
@Override
public Map<String, Object> vehicleCheckYear(Map<String, Object> paramsMap)
		throws Exception {
	Map<String,Object> resultMap = new HashMap<>();
	String[] ids =  paramsMap.get("ids").toString().split(",");
	paramsMap.put("ids", ids);
	int count = vehicleDao.updateForAddOneChekYears(paramsMap);
	if( count >= 0){
		//查询车辆信息
		List<Map<String, Object>> listMap = vehicleDao.selectVehicleByIds(paramsMap);
		listMap.stream().forEach(map->{
			map.put("operateuser", paramsMap.get("operateuser"));
			map.put("manageorganization", paramsMap.get("manageorganization"));
			map.put("dbcode", paramsMap.get("dbcode"));
		});	
		if(listMap != null && listMap.size() > 0){
			//批量新增操作日志
			int counts = vehicleDao.addBatchVehicleOperateLog(listMap);
			if(counts > 0){
				resultMap.put("returnCode", 1);
				resultMap.put("ListData", count);
				resultMap.put("returnMsg", "年审成功");
			}else{
				throw new Exception();
			}
		}else{
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "年审成功");
			resultMap.put("ListData", count);
		}	
    }else{
    	resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "年审失败");
    }
	return resultMap;
}

@Override
public Map<String, Object> queryRelationVehicle(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<Map<String,Object>> vehicleList = vehicleDao.queryRelationVehicle(paramsMap);
	if( vehicleList != null && vehicleList.size() > 0){
    	resultMap.put("returnCode", 1);
		resultMap.put("ListData", vehicleList);
    }else{
    	resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
    }
	return resultMap;
}

@Override
public Map<String, Object> queryVehicleByNumber(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> vehicleInfo = vehicleDao.queryVehicleByNumber(paramsMap);
	if(vehicleInfo != null){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData", vehicleInfo);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统查询不到该条信息");
	}
	return resultMap;
}

@Override
public int updateTicketServer(Map<String, Object> paramsMap) throws DataAccessException {
	int flag = 1;
	int j = vehicleDao.updateTicketDao(paramsMap);
	if(j > 0){
		paramsMap.put("usertype", paramsMap.get("usedept"));
		int i = vehicleDao.updateTicketDetailDao(paramsMap);
		if(i > 0){
			flag = 1;
		}else{
			flag = 0;
		}
	}else{
		flag = 0;
	}
	return flag;
}

@Override
public Map<String, Object> queryVehicleByWx(Map<String, Object> paramsMap) throws DataAccessException {
	return vehicleDao.queryVehicleByWx(paramsMap);
}

@Override
public List<Map<String, Object>> queryVehicleByPietype(Map<String, Object> paramsMap) throws DataAccessException {
	return vehicleDao.queryVehicleByPietype(paramsMap);
}

@Override
public List<Map<String, Object>> selectEgalBehavoir(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.selectEgalBehavoir(paramsMap);
}

@Override
public List<Map<String, Object>> seletCompanyNameCount(Map<String, Object> paramsMap) throws DataAccessException {
	List<Map<String, Object>> list = vehicleDao.seletCompanyNameCount(paramsMap);
	Map<String, Object> map = new HashMap<>();
	map.put("CompanyName","黑车");
	map.put("CompanyNameCount",vehicleDao.seletCompanyNameCountnull(paramsMap));
	list.add(map);
	return list;
}

@Override
public List<Map<String, Object>> seletTrainingCount(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.seletTrainingCount(paramsMap);
}

@Override
public List<Map<String, Object>> seletOverdueTrainingCount(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.seletOverdueTrainingCount(paramsMap);
}

@Override
public List<Map<String, Object>> seletCompanyVehicleCount(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.seletCompanyVehicleCount(paramsMap);
}

@Override
public List<Map<String, Object>> seletCompanyOrderCount(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.seletCompanyOrderCount(paramsMap);
}

@Override
public List<Map<String, Object>> seletCompanyOrderTimeGroup(
		Map<String, Object> paramsMap) throws DataAccessException {
	return vehicleDao.seletCompanyOrderTimeGroup(paramsMap);
}

@Override
public List<Map<String, Object>> findCompanyName(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.findCompanyName(paramsMap);
}

@Override
public List<Map<String, Object>> findCarOnlineCount(
		Map<String, Object> paramsMap) throws DataAccessException {
	return vehicleDao.findCarOnlineCount(paramsMap);
}

@Override
public Map<String, Object> getCountByBrandType(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	//查询票证号
	List<Map<String, Object>> brandTypeCount = vehicleDao.getCountByBrandType(paramsMap); 
	if(brandTypeCount != null && brandTypeCount.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "操作成功");
		resultMap.put("ListData", brandTypeCount);
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "未查询到数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> queryVehicleInfo(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	String vehiclestatus = Optional.ofNullable(paramsMap.get("vehiclestatus")).orElse("").toString();
	paramsMap.put("vehiclestatus", vehiclestatus.equals("")?"":vehiclestatus.split(","));
	String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
	if(companyid.contains("-")){
		paramsMap.put("companyid","");
	}else{
		paramsMap.put("companyid",companyid.equals("")?"":companyid.split(","));
	}
	List<Map<String,Object>> vehicleInfos = vehicleDao.queryVehicleInfo(paramsMap);
	if(vehicleInfos != null && vehicleInfos.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",vehicleInfos);
	    resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> resetDriverCarRelation(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> resetInfo = vehicleDao.resetDriverCarRelation(paramsMap);
	if(resetInfo != null && resetInfo.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",resetInfo);
	    resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "操作失败");
	}
	return resultMap;
}

@Override
public Map<String, Object> getVehicleCountInfo(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<Map<String,Object>> resultList = vehicleDao.getVehicleCountInfo(paramsMap);
	if(resultList != null && resultList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",resultList);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统未查到数据");
	}
	return resultMap;
}

@Override
public List<Map<String, Object>> findVehicleToCarRentalService(Map<String, Object> paramsMap)
		throws DataAccessException {
	// TODO Auto-generated method stub
	return vehicleDao.findVehicleToCarRentalDao(paramsMap);
}

@Override
public Map<String, Object> getTikeDetailInfoByTicketId(
		Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	List<Map<String,Object>> tikeDetaiList = vehicleDao.getTikeDetailInfoByTicketId(paramsMap);
	int tikeDetaiCounts = vehicleDao.getTikeDetailCountByTicketId(paramsMap);
	if(tikeDetaiList != null && tikeDetaiList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",tikeDetaiList);
		resultMap.put("TotalCount",tikeDetaiCounts);
		resultMap.put("TotalPage",tikeDetaiCounts % pagesize >0 ? tikeDetaiCounts/pagesize + 1 : tikeDetaiCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("errorCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> getInfofromTikeDetail(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	List<Map<String,Object>> resultList = vehicleDao.getInfofromTikeDetail(paramsMap);
	if(resultList != null && resultList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",resultList);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统未查到数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> checkNumIsExist(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	Map<String,Object> resultList = vehicleDao.checkNumIsExist(paramsMap);
	if(resultList != null && resultList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",resultList);
		resultMap.put("returnMsg", "票证号已存在");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "没有该票证号");
	}
	return resultMap;
}
@Override
public Map<String, Object> queryAllVehicleInfo(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	String vehiclestatus = Optional.ofNullable(paramsMap.get("vehiclestatus")).orElse("").toString();
	paramsMap.put("vehiclestatus", vehiclestatus.equals("")?"":vehiclestatus.split(","));
	if(Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString().contains("-")){
		paramsMap.put("companyid","");
	}
	List<Map<String,Object>> vehicleInfos = vehicleDao.queryAllVehicleInfo(paramsMap);
	if(vehicleInfos != null && vehicleInfos.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",vehicleInfos);
	    resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}
@Override
public Map<String, Object> addLockForVehicle(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int i = vehicleDao.addLockForVehicle(paramsMap);
	if(i > 0){
		resultMap.put("returnCode", 1);
	    resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "添加锁定失败");
	}
	return resultMap;
}
@Override
public Map<String, Object> unlockForVehicle(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int j = vehicleDao.unlockForVehicle(paramsMap);
	if(j > 0){
		resultMap.put("returnCode", 1);
	    resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "解除锁定失败");
	}
	return resultMap;
}

@Override
public List<Map<String, Object>> queryVehicleByCname(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.queryVehicleByCname(paramsMap);
}

public List<Map<String, Object>> selectServiceEvaluation(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.selectServiceEvaluation(paramsMap);
}

public List<Map<String, Object>> selectVehicleCname(Map<String, Object> paramsMap)
		throws DataAccessException {
	return vehicleDao.selectVehicleCname(paramsMap);
}

@Override
public Map<String,Object> queryAllVehicle(Map<String, Object> paramsMap) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
	paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
	List<Map<String,Object>> vehicleList = vehicleDao.queryAllVehicle(paramsMap);
	int vehicleCounts = vehicleDao.queryAllVehicleCounts(paramsMap);
	if(vehicleList != null && vehicleList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",vehicleList);
		resultMap.put("TotalCount",vehicleCounts);
		resultMap.put("TotalPage",vehicleCounts % pagesize >0 ? vehicleCounts/pagesize + 1 : vehicleCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

}
